#Include "Protheus.ch"

User Function TstMata103()

Local aCabec := {}
Local aItens := {}
Local aLinha := {}
Local nOpc   := 3

Private lMsErroAuto := .F.

aAdd(aCabec, {"F1_TIPO"   , "N"             , Nil})
aAdd(aCabec, {"F1_FORMUL" , "N"             , Nil})
aAdd(aCabec, {"F1_DOC"    , "284986"        , Nil})
aAdd(aCabec, {"F1_SERIE"  , "U"             , Nil})
aAdd(aCabec, {"F1_EMISSAO", CToD("07/02/11"), Nil})
aAdd(aCabec, {"F1_FORNECE", "000518"        , Nil})
aAdd(aCabec, {"F1_LOJA"   , "01"            , Nil})
aAdd(aCabec, {"F1_ESPECIE", "CTR"           , Nil})
aAdd(aCabec, {"F1_COND"   , "021"           , Nil})
//aAdd(aCabec, {"F1_DESPESA", 28.56           , Nil})		
aAdd(aCabec, {"E2_NATUREZ", "20301"         , Nil})
//aAdd(aCabec, {"E2_VENCTO", CToD("14/04/11") , Nil})

aAdd(aLinha, {"D1_COD"   , "600083"        , Nil})
aAdd(aLinha, {"D1_QUANT" , 1               , Nil})
aAdd(aLinha, {"D1_VUNIT" , 28.56           , Nil})
aAdd(aLinha, {"D1_TOTAL" , 28.56           , Nil})
aAdd(aLinha, {"D1_TES"   , "032"           , Nil})


aAdd(aItens, aLinha)

BeginTran()

	MsExecAuto({|x, y, z| MATA103(x, y, z)}, aCabec, aItens, nOpc)
	
	IF !lMsErroAuto
		SE2->(dbSetOrder(6))
	
		IF SE2->(MsSeek(xFilial() + "000518" + "01" + "U  " + "284986"))
			SE2->E2_VENCTO  := CToD("14/04/11")
			SE2->E2_VENCREA := DataValida(CToD("14/04/11"), .T.)
			SE2->E2_VENCORI := CToD("14/04/11")
		EndIF
	
		EndTran()
	Else
		MostraErro()
		DisarmTransaction()
	EndIF
		
MsUnlockAll()

MsgInfo("Fim!")

Return Nil